//
//  KATTableHeader.h
//  KATFramework
//
//  Created by Kantice on 16/7/14.
//  Copyright © 2016年 KatApp. All rights reserved.
//  列表头(基类)

#import <UIKit/UIKit.h>
#import "KATMacros.h"
#import "KATAppUtil.h"


#define THEADER_STATE_INIT -1
#define THEADER_STATE_READY 0
#define THEADER_STATE_PULLING 1
#define THEADER_STATE_RELEASE 2
#define THEADER_STATE_LOADING 3
#define THEADER_STATE_FINISH 4


@class KATTableHeader;

///事件代理(给列表提供回调)
@protocol KATTableHeaderDelegate <NSObject>

@optional

///开始加载
- (void)tableHeaderDidStartLoad:(KATTableHeader *)header;

@end



///状态代理(子类需要实现)
@protocol KATTableHeaderStateDelegate <NSObject>

@required

///下拉中，进度为1时完成
- (void)headerPullWithProgress:(float)progress;

///下拉完成
- (void)headerFinishPull;

///开始加载
- (void)headerStartLoad;

///完成加载
- (void)headerFinishLoad;

///加载完成后恢复
- (void)headerRestoreAfterLoad;

@end



@interface KATTableHeader : UIView
{
    dispatch_queue_t _headerQueue;
}


#pragma -mark 属性

///依附的scrollView
@property(nonatomic,assign) UIScrollView *scrollView;

///状态
@property(nonatomic,assign) int state;

///完整的下拉高度(默认为控件高度2倍)
@property(nonatomic,assign) float dragHeight;

///是否释放时才加载
@property(nonatomic,assign) BOOL isReleaseToLoad;

///加载完成后的隐藏时间(默认为0.8秒)
@property(nonatomic,assign) double animationFinishDuration;

///是否锁定(锁定后无法加载，防止冲突时使用)
@property(nonatomic,assign) BOOL locked;

///是否忽略冲突
@property(nonatomic,assign) BOOL ignoreConflicts;

///状态代理(给子类提供状态回调)
@property(nonatomic,assign) id<KATTableHeaderStateDelegate> stateDelegate;

///事件代理
@property(nonatomic,assign) id<KATTableHeaderDelegate> eventDelegate;


#pragma -mark 类方法

///获取实例
+ (instancetype)tableHeader;


#pragma -mark 对象方法

///初始化数据
- (void)initWithHeight:(float)height andScrollView:(UIScrollView *)scrollView;

///完成加载
- (void)finishLoad;

///直接加载
- (void)load;

///释放内存
- (void)dealloc;


@end



